import KoaRouter from 'koa-router'
import Config from '@/config/Config'
import validator from '@/middlewares/validator'
import { Models } from '@/common/typings/modle'
import { command } from '@/server/mysql'
import { Success } from '@/core/HttpException'
import schema from '@/common/api-json-schema/mini/points/getCurrentPoints'
const router = new KoaRouter({
  prefix: `${Config.API_PREFIX}v2/mini/points`,
})
router.post('/getCurrentPoints', validator(schema, 'body'), async (ctx: Models.Ctx) => {
  const { familyId } = ctx.request.body as any
  const data = (
    await command(`SELECT t.field1 FROM mini_family t WHERE t.family_id = '${familyId}' AND t.row_type = 'info';`, true)
  ).results
  throw new Success({
    data: data[0].field1,
  })
})
export default router
